package com.aind.cart.service.impl;

import com.aind.cart.dao.CartMapper;
import com.aind.cart.model.Cart;
import com.aind.cart.model.CartExample;
import com.aind.cart.service.CartService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by lpeng on 2017/2/22.
 */
@Service
public class CartServiceImpl implements CartService {

    private static Logger logger = Logger.getLogger(CartServiceImpl.class);

    @Autowired
    private CartMapper cartMapper;

    @Override
    public List<Cart> getCartListByUserId(Long userId) {
        List<Cart> carts = cartMapper.selectBookInCartByUserId(userId);
        for (Cart cart : carts) {
            cart.setSubtotal(cart.getCurrentPrice().multiply(new BigDecimal(cart.getQuantity())));
        }
        return carts;
    }
}
